﻿// <copyright file="DialogHelper.cs" company="BerlinSoft">
// Copyright (c) 2009 All Right Reserved
// </copyright>
// <author>Wernfried Schwenkner</author>
// <email>wernfried@schwenkner.de</email>
// <date>2009-10-21</date>
// <summary>
// Contains the DialogHelper class.
// </summary>

using System;
using System.Windows.Forms;

namespace SenseTimeTracker.Misc
{
	/// <summary>
	/// Class implements the dialog helper
	/// </summary>
	public class DialogHelper : IDisposable
	{
		/// <summary>
		/// Field contains the saved header
		/// </summary>
		private readonly string savedHeader;

		/// <summary>
		/// Field contains the saved form
		/// </summary>
		private readonly Form savedForm;

		/// <summary>
		/// Initializes a new instance of the <see cref="DialogHelper"/> class.
		/// </summary>
		/// <param name="form">The form to be hidden</param>
		public DialogHelper(Form form)
		{
			savedHeader = form.Text;
			savedForm = form;
			form.Text = string.Empty;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="DialogHelper"/> class.
		/// </summary>
		/// <param name="form">The form to be hidden</param>
		/// <param name="newForm">The new dialog</param>
		public DialogHelper(Form form, Control newForm)
		{
			newForm.Text = form.Text;
			savedHeader = form.Text;
			savedForm = form;
			form.Text = string.Empty;
		}

		#region IDisposable Members

		/// <summary>
		/// Disposes the object
		/// </summary>
		public void Dispose()
		{
			savedForm.Text = savedHeader;
		}

		#endregion
	}
}
